/**
 * Created by Administrator on 2017/3/21.
 */
import React, {Component,Fragment} from 'react';
import {Form, Input, Radio, Select,   InputNumber,
  Upload, } from 'antd';
import {connect} from 'dva';
import moment from 'moment'
import request from '@/utils/request';
const FormItem = Form.Item;
const { TextArea } = Input;
const RadioGroup = Radio.Group;
const Option = Select.Option;
class AddPoliciesForm extends Component {
  constructor(props) {
    super(props);
    this.state = {
      fileList:[]
    };
  }

  componentDidMount() {
  }
  render() {
    const formItemLayoutWithLabel = {
      labelCol: {
        xs: {span: 24},
        sm: {span: 6},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 15},
      }
    };

    const {getFieldDecorator} = this.props.form;
    return (
      <div>
        <Form onSubmit={this.handleSubmit}>
          {
            this.props.type==='in'&&
              <Fragment>
                <FormItem
                  label={'入库类型'}
                  {...formItemLayoutWithLabel}
                >
                  {getFieldDecorator(`type`, {
                    initialValue:'write',
                    rules: [{ required: true }],


                  })(
                    <Select >
                      {
                        [{key:'write',value:'库存录入'},{key:'purchase',value:'采购入库'}].map((item,index)=>{
                          return <Option key={index} value={item.key}>{item.value}</Option>
                        })
                      }
                    </Select>
                  )}
                </FormItem>
                <FormItem
                  label={'入库状态'}
                  {...formItemLayoutWithLabel}
                >
                  {getFieldDecorator(`status`, {
                    initialValue:'-1',
                    rules: [{ required: true }],
                  })(
                    <Select >
                      {
                        [{key:'-1',value:'未入库'},{key:'1',value:'已入库'}].map((item,index)=>{
                          return <Option key={index} value={item.key}>{item.value}</Option>
                        })
                      }
                    </Select>
                  )}
                </FormItem>
              </Fragment>
          }
          {
            this.props.type==='out'&&
            <Fragment>
              <FormItem
                label={'出库类型'}
                {...formItemLayoutWithLabel}
              >
                {getFieldDecorator(`type`, {
                  initialValue: 'take',
                  rules: [{ required: true, message: '请输入出库数量' }],
                })(
                  <Select >
                    {
                      [{key:'take',value:'领料出库'},{key:'lost',value:'库存报损'}].map((item,index)=>{
                        return <Option key={index} value={item.key}>{item.value}</Option>
                      })
                    }
                  </Select>
                )}
              </FormItem>
              <FormItem
                label={'出库状态'}
                {...formItemLayoutWithLabel}
              >
                {getFieldDecorator(`status`, {
                  initialValue: '-1',
                  rules: [{ required: true, message: '请输入出库数量' }],
                })(
                  <Select >
                    {
                      [{key:'-1',value:'未出库'},{key:'1',value:'已出库'}].map((item,index)=>{
                        return <Option key={index} value={item.key}>{item.value}</Option>
                      })
                    }
                  </Select>
                )}
              </FormItem>
            </Fragment>
          }
          <FormItem
            label={'库存数量'}
            {...formItemLayoutWithLabel}
          >
            {getFieldDecorator('all_count', {
              initialValue: this.props.editRecord? this.props.editRecord.count:'',
            })(
              <Input disabled/>
            )}
          </FormItem>
          {
            this.props.type==='in'&&
            <Fragment>
              <FormItem
                label={'入库数量'}
                {...formItemLayoutWithLabel}
              >
                {getFieldDecorator('count', {
                  initialValue: '0',
                  rules: [{ required: true, message: '请输入入库数量' }],
                })(
                  <InputNumber style={{width:'100%'}} />
                )}
              </FormItem>
            </Fragment>
          }
          {
            this.props.type==='out'&&
            <Fragment>
              <FormItem
                label={'出库数量'}
                {...formItemLayoutWithLabel}
              >
                {getFieldDecorator('count', {
                  initialValue: '0',
                  rules: [{ required: true, message: '请输入出库数量' }],
                })(
                  <InputNumber style={{width:'100%'}} />
                )}
              </FormItem>
            </Fragment>
          }
          <FormItem
            label={'备注'}
            {...formItemLayoutWithLabel}
          >
            {getFieldDecorator('remark', {
              initialValue: this.props.editRecord? this.props.editRecord.remark:'',
            })(
              <Input />
            )}
          </FormItem>
        </Form>
      </div>
    );
  }
}

const AddPoliciesFormWrap = Form.create()(AddPoliciesForm);
export default connect()(AddPoliciesFormWrap);


